<!--
  Copyright © 2016 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="tracker-content">
  <div class="tracker-top-search"
       ng-if="!$state.params.iframe">
    <div class="tracker-search-bar">
      <div class="form-group has-feedback" ng-keypress="MainController.search($event)">
        <input type="text"
               class="form-control"
               placeholder="Search datasets"
               ng-model="MainController.searchQuery">
        <span class="fa fa-search form-control-feedback"></span>
      </div>
    </div>
    <cask-resource-center-button></cask-resource-center-button>
  </div>

  <div class="tracker-metrics">
    <div class="row text-center">
      <div class="col-md-4">
        <div class="metric-heading">
          <p>Most Active Applications</p>
          <p>Last 7 days</p>
        </div>
        <div class="metric-container">
          <my-top-entity-graph
            type="applications"
            start="'now-7d'"
            end="'now'"
            limit="5">
          </my-top-entity-graph>
        </div>
      </div>
      <div class="col-md-4">
        <div class="metric-heading">
          <p>Most Active Programs</p>
          <p>Last 7 days</p>
        </div>
        <div class="metric-container">
          <my-top-entity-graph
            type="programs"
            start="'now-7d'"
            end="'now'"
            limit="5">
          </my-top-entity-graph>
        </div>
      </div>
      <div class="col-md-4">
        <div class="metric-heading">
          <p>Most Active Datasets</p>
          <p>Last 7 days</p>
        </div>
        <div class="metric-container">
          <table ng-if="MainController.serviceUnavailable === false && MainController.topDatasets.length > 0"
                class="table">
            <thead>
              <th class="text-center">Dataset</th>
              <th colspan="2"
                  class="text-center">
                Programs
                <div class="clearfix">
                  <span class="pull-left">Reading</span>
                  <span class="pull-right">Writing</span>
                </div>
              </th>
            </thead>
            <tbody>
              <tr ng-repeat="metric in ::MainController.topDatasets">
                <td class="text-left">

                  <a ng-if="metric.entityType === 'dataset'"
                    ui-sref="tracker.detail.entity.metadata({entityType: 'datasets', entityId: metric.entityName})">
                    <span uib-tooltip="{{ ::metric.entityName }}"
                      tooltip-ellipsis="{{ ::metric.entityName }}"
                      tooltip-enable="metric.entityName.length > 15"
                      tooltip-append-to-body="true"
                      tooltip-class="tracker-tooltip"
                      tooltip-placement="top">
                      <i class="icon-datasets"></i>
                      {{ ::metric.entityName }}
                    </span>
                  </a>
                  <a ng-if="metric.entityType === 'stream'"
                    ui-sref="tracker.detail.entity.metadata({entityType: 'streams', entityId: metric.entityName})">
                    <span uib-tooltip="{{ ::metric.entityName }}"
                      tooltip-ellipsis="{{ ::metric.entityName }}"
                      tooltip-enable="metric.entityName.length > 15"
                      tooltip-append-to-body="true"
                      tooltip-class="tracker-tooltip"
                      tooltip-placement="top">
                      <i class="icon-streams"></i>
                      {{ ::metric.entityName }}
                    </span>
                  </a>
                </td>
                <td class="text-center">{{ ::metric.read }}</td>
                <td class="text-center">{{ ::metric.write }}</td>
              </tr>
              <tr ng-if="MainController.emptyRows === true"
                ng-repeat="row in MainController.totalEmptyRows"
                class="empty-row">
                <td></td>
                <td></td>
                <td></td>
              </tr>
            </tbody>
          </table>
          <div ng-if="MainController.topDatasets.length === 0"
              class="well">
            <p>No datasets found</p>
          </div>
          <div ng-if="MainController.serviceUnavailable === true"
              class="well">
            <p>Service unavailable</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
